package wangwenjun.phase1.interrupt;

import util.ThreadUtil;

/**
 * @author ChangLiang
 * @date 2020/5/29
 */
public class ThreadIsInterruptedV1 {

    public static void main(String[] args) {
        // InterruptedException will not cause loop stop
        // 非中断方法，其不会响应中断
        Thread thread = new Thread() {
            @Override
            public void run() {
                while (true) {
                    // do nothing, just empty loop
                }
            }
        };

        thread.start();
        ThreadUtil.sleepForMilliSeconds(2);
        System.out.printf("Thread is interrupted ? %s\n", thread.isInterrupted());
        thread.interrupt();
        ThreadUtil.sleepForMilliSeconds(2);
        System.out.printf("Thread is interrupted ? %s\n", thread.isInterrupted());

        // output: false true
    }
}
